
public class ArrayTest {

	public static void main(String[] args) {

		Test1();
		Test2();

	}

	static void Test1() {
		int a[] = { 1, 2, 3, 4, 5 }, b[];//此处的b并没有自己的存储空间。
		b = a;//此处不是传值，而是传引用！也就是说两个其实是一个地址,一旦修改，就全部修改了。
		System.out.println(a == b);
		System.out.println(a.equals(b));
		b[1] = 10;

		for (int m : a) {
			System.out.print(m + ",");
		}
		System.out.println();
		for (int m : b) {
			System.out.print(m + ",");
		}
		System.out.println();
	}

	static void Test2() {
		int a[] = { 1, 2, 3, 4, 5 }, b[] = new int[a.length];//b数组是新建了自己的存储空间的
		for (int i = 0; i < a.length; i++) {
			b[i] = a[i];//此处是传值，互相就没有影响
		}
		System.out.println(a == b);
		System.out.println(a.equals(b));

		b[1] = 10;

		for (int m : a) {
			System.out.print(m + ",");
		}
		System.out.println();
		for (int m : b) {
			System.out.print(m + ",");
		}
	}

}
